#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int n,m,maxs=0,dx[5]={0,0,0,1,-1},dy[5]={0,-1,1,0,0};
char a[2010][2010];
bool book[2010][2010];
int doit(int x,int y)
{
	int x1=x,y1=y,s=0;
	while (a[x1][y1-1]!='#')
	{
		y1-=1;
		if (a[x1][y1]=='G')
			s++;
	}
	x1=x,y1=y;
	while (a[x1][y1+1]!='#')
	{
		y1+=1;
		if (a[x1][y1]=='G')
			s++;
	}
	x1=x,y1=y;
	while (a[x1-1][y1]!='#')
	{
		x1-=1;
		if (a[x1][y1]=='G')
			s++;
	}
	x1=x,y1=y;
	while (a[x1+1][y1]!='#')
	{
		x1+=1;
		if (a[x1][y1]=='G')
			s++;
	}
	return s;
}
struct all
{
	int x,y;
}k[4000100];
int main ()
{
	freopen("boom.in","r",stdin);
	freopen("boom.out","w",stdout);
	cin>>n>>m>>k[1].x>>k[1].y;
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
			cin>>a[i][j];
	maxs=doit(k[1].x,k[1].y);
	memset(book,true,sizeof(book));
	book[k[1].x][k[1].y]=false;
	int head=0,tail=1,xx,yy;
	while (head<tail)
	{
		head++;
		for (int i=1;i<=4;i++)
		{
			xx=k[head].x+dx[i];
			yy=k[head].y+dy[i];
			if (a[xx][yy]=='.'&&book[xx][yy]==true)
			{
				tail++;
				k[tail].x=xx;
				k[tail].y=yy;
				book[xx][yy]=false;
				int u=doit(xx,yy);
				if (u>maxs)
					maxs=u;
			}
		}
	}
	cout<<maxs;
	return 0;
}
